package com.fotkidemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import com.fotkidemo.beans.Image;

/**
 * Created with IntelliJ IDEA.
 * User: roma
 * Date: 6/21/12
 * Time: 3:34 PM
 * To change this template use File | Settings | File Templates.
 */

//Activity отвечает за отображение фоток альбома
public class ImagesShowActivity extends FragmentActivity implements ImagesFragment.OnImagesClickListener {
    private static final String TAG = "ImagesFragment";

    public static final String EXTRA_URL = "extra_url";
    public static final String ALBUM_CACHE = "album_cache";
    public static final String IMAGE_COUNT = "image_count";

    private String album_cache;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final String url = getIntent().getStringExtra(EXTRA_URL);
        album_cache = getIntent().getStringExtra(ALBUM_CACHE);
        if (url != null && album_cache != null) {
            if (getSupportFragmentManager().findFragmentByTag(TAG) == null) {
                final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                ft.add(android.R.id.content, ImagesFragment.newInstance(url, album_cache), TAG);
                ft.commit();
            }
        }
    }

    @Override
    public void onImageClick(Image image, int position) {
        Intent intent = new Intent(this, ImageDetailActivity.class);
        intent.putExtra(ImageDetailActivity.EXTRA_URL, image.getHrefL());
        intent.putExtra(ImageDetailActivity.ALBUM_CACHE, album_cache);
        intent.putExtra(ImageDetailActivity.IMAGE_COUNT, getIntent().getIntExtra(IMAGE_COUNT, 0));
        intent.putExtra(ImageDetailActivity.EXTRA_IMAGE, position);
        startActivity(intent);
    }
}